
<%@ page import="com.gasstation.GasPurchases; java.text.DecimalFormat" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'gasPurchases.label', default: 'GasPurchases')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></span>
        </div>
        <div class="body">
            <h1><g:message code="default.list.label" args="[entityName]" /></h1>
            <g:form action="listAsPerMonth">
            	<% Date date = (monthYear==null)?new Date():monthYear %>
            	<g:datePicker name="monthYear" value="${date}" precision="month"/> <g:submitButton name="showList" value="Go"/>
            
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="list">
                <table>
                    <thead>
                        <tr>
                            <g:sortableColumn property="transactionOn" title="Date" />
                        
                            <g:sortableColumn property="regularNetGallons" title="Regular Gal" />
                            <g:sortableColumn property="midGradeNetGallons" title="Mid Grade Gal" />
                            <g:sortableColumn property="premiumNetGallons" title="Premium Gal" />
                            <g:sortableColumn property="totalGasPurchases" title="Total Gas Gal" />
                            <g:sortableColumn property="regularPricePerGallon" title="Regular Price/Gal" />
                            <th>Regular $</th>
                            <g:sortableColumn property="midGradePricePerGallon" title="MidGrade Price/Gal" />
                            <th>MidGrade $</th>
                            <g:sortableColumn property="premiumPricePerGallon" title="Premium Price/Gal" />
                            <th>Premium $</th>
                            <th>Total Gas $</th>
                            <%--<th>Edit/Delete</th>--%>
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${gasPurchasesInstanceList}" status="i" var="gasPurchasesInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                        
                            <td><g:formatDate date="${gasPurchasesInstance.transactionOn}" format="MM/dd/yyyy" /></td>
                        	<%
								double regGal = gasPurchasesInstance.regularNetGallons
								double midGal = gasPurchasesInstance.midGradeNetGallons
								double premiumGal = gasPurchasesInstance.premiumNetGallons
								double totalGal = regGal+midGal+premiumGal
							DecimalFormat df = new DecimalFormat("#.####");
							String totalGalDisplay=df.format(totalGal)
							 %>
                            <td><%=regGal %></td>
                            <td><%=midGal %></td>
                            <td><%=premiumGal %></td>
                            <td><%=totalGalDisplay %></td>
                            <%
								double regPerGal=gasPurchasesInstance.regularPricePerGallon
								double midPerGal=gasPurchasesInstance.midGradePricePerGallon
								double premiumPerGal=gasPurchasesInstance.premiumPricePerGallon
								double regDollar = regPerGal*regGal
								double midDollar = midPerGal*midGal
								double premiumDollar = premiumPerGal*premiumGal
								String regDollarDisplay = df.format(regDollar)
								String midDollarDisplay = df.format(midDollar)
								String premiumDollarDisplay = df.format(premiumDollar)
								double totalDollar = regDollar+midDollar+premiumDollar
								String totalDollarDisplay = df.format(totalDollar)
							 %>
                        	<td>$<%=regPerGal%></td>
                        	<td>$<%=regDollarDisplay %></td>
                            <td>$<%=midPerGal%></td>
                            <td>$<%=midDollarDisplay %></td>
                            <td>$<%=premiumPerGal%></td>
                            <td>$<%=premiumDollarDisplay %></td>
                            <td>$<%=totalDollarDisplay %></td>
                            <%--<td><g:link action="edit" id="${gasPurchasesInstance.id}">Edit</g:link>
                            <g:link action="delete" id="${gasPurchasesInstance.id}" onclick="return confirm('Are you sure');">Delete</g:link>--%></td>
                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>
            <div class="paginateButtons">
                <g:paginate total="${gasPurchasesInstanceTotal}" />
            </div>
            </g:form>
        </div>
    </body>
</html>
